﻿
import A2.BE.utils;
import A2.BE.V3;
import mx.utils.Delegate;
import mx.transitions.Tween;
import mx.transitions.easing.*;
import com.darronschall.DynamicRegistration;
import gs.*; 
import A2.HandDoBtn;
import A2.utils.uString;
import A2.utils.Pos ;

/**
 * ...
 * @author wangjun
 */
class A2.ui.cluePannelV2 extends A2.ui.Pannel
{
	var btnPart	:MovieClip;
	var tfPart	:MovieClip;
	var tf		:TextField;
	var btn_ruler	:MovieClip;
	var btn_real	:MovieClip;
	var scope	:MovieClip;
	var ntf		:MovieClip;
	
	var btn_arr	:Array = [];
	var func_arr:Array = [];
	var autoClose_arr:Array = [];
	
	public function cluePannelV2 (scope:MovieClip) 
	{
		super();
		
		tf.selectable 	= false;
		btn_ruler 		= btnPart.ruler; 	
		
	} 

	//this._visible = false; 
 
	function show(str:String, orderGroup:Array ) { 		 
		if (this.scope == null) throw new Error( "!! A2.ui.cluePannelV2::show 缺少scope");
		
		removeMovieClip(btn_real);
		btn_real 		= btnPart.createEmptyMovieClip('real',1); 
		
		 var btns:Array 	= [];
		 var funs:Array 	= [];
		 var autos:Array 	= [];
		 
		 
		for (var i:Number = 0; i < orderGroup.length; i++) 
		{
			btns.push	(orderGroup[i].btn);
			funs.push	(orderGroup[i].callback);
			autos.push	(orderGroup[i].autoClose);
		} 
				 
	//------------------------  华丽的分割线 --------------------------  文本
		tf.text = uString.replace(str, '`', '\r'); 
		 
		A2.utils.uBitmap.bmTxt(tf, ntf);		
		
	//------------------------  华丽的分割线 --------------------------  按钮 
		
		trace( this.btn_arr );
		
		 this.btn_arr 		= [];
		 this.func_arr 		= [];
		 this.autoClose_arr = [];
		 
		var realNum:Number = 0;
		var len:Number 	= btns.length;
		var xx:Number 	= 0;
		 
		
		for (var i:Number = 0; i < len; i++) 
		{
								
			var b = btn_real.attachMovie(btns[i], 'btn'+i.toString(), i); 
			if (b != null) {
				
				if (b.constructor == Button) {
					
					//trace( "注意!! A2.ui.cluePannelV2::show 所附加的MC是Button");
					
				}
				
				realNum++;
				b._x += xx;
				xx += b._width + 30;
				
				
				btn_arr.push		(b);
				func_arr.push		(funs[i]);
				autoClose_arr.push	(autos[i]);
				 
				new V3(this, b, 
					function(evt) {  
						Delegate.create(this.scope, this.func_arr[evt.id])(evt); 
						var autoClose:Boolean = this.autoClose_arr[evt.id];
						//trace('autoClose ' + autoClose);
						if (autoClose == null || autoClose == true) {
							utils.kill()
							close(this.reInitBtn);							
							removeMovieClip(btn_real);
						}
					}
					
				) 
			}
		}    
		//Pos.centerMutiple(btn_ruler, btn_arr ); 
		
																	// 居中对齐
		Pos.center(btn_ruler, btn_real);
		btn_ruler._visible = false;
		 
		this.open(true);		
		 
	} 
	
}